#include <mqueue.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
  int flags, opt;
  mqd_t mqd;
  unsigned int prio;
  flags = O_WRONLY;
  while ((opt = getopt(argc, argv, "n")) != -1) {
    switch(opt) {
    case 'n': 
      flags |= O_NONBLOCK;
      break;
    default:
      printf("wrong options\n");
    }
  }
  mqd = mq_open(argv[optind], flags);
  if (mqd == (mqd_t)-1)
    printf("Failed to open mq %s\n",argv[optind]);
  prio = argc>optind+2 ? atoi(argv[optind+2]) : 0;
  if (mq_send(mqd, argv[optind+1], strlen(argv[optind+1]),prio)==-1)
    printf("mq_send error");
  return 0;
}
